home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Zen & the Art of Resourc…The BMUG Guide to ResEdit
/
Zen and the Art of Resource Editing - The BMUG Guide to ResEdit (1995).iso
/
ResEdit 2.1.3
/
Examples
/
CExamples
/
Source
/
ICON.Pick.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-15
|
5KB
|
146 lines
/*
COPYRIGHT (C) 1984-1990 Apple Computer,Inc.
All rights reserved
*/
/* Icon Resource Picker */
/* This is the Icon resource picker example.
The general scheme is that a List structure is created whose cells
contain the ID's of this resource type. A drawproc is installed in the List
record which is called to display the resource. */
#include <types.h>
#include <memory.h>
#include <menus.h>
#include <resources.h>
#include <lists.h>
#include "ResEd.h"
#define iconMenuID 10 /* Just one of ResEdit's menus. */
#define listCellSizeH 0x38
#define listCellSizeV 0x42
/* Needs to be 2 wide so that I can always tell a 2 dimensional list from a normal text list. */
#define minIconsPerRow 2
#define ICONMinWindowWidth (minIconsPerRow * listCellSizeH) + theScrollBar
#define ICONMinWindowHeight listCellSizeV
typedef struct IconPickRec {
ParentHandle father; /* Back ptr to dad */
Str255 fName; /* Max 255 characters. */
WindowPtr wind; /* Picker window */
Boolean rebuild; /* Flag set to indicate that window should be rebuilt */
Boolean spare1; /* Not used here */
unsigned char windowType;
ResType theResType; /* Type of the resource being picked or edited. */
short theResFile; /* The home resfile of the window. */
short codeResID; /* Resource ID of the RSSC resource containing the picker or editor. */
Handle spare; /* Not used here */
ResType rType; /* Type for this picker */
long rSize; /* size of a null resource */
short minWindowWidth; /* Use when the window is grown. */
short minWindowHeight;
ListHandle instances; /* List of instances */
short nInsts; /* Number of instances */
unsigned char viewBy; /* Current view type */
Boolean showAttributes; /* Show attrs in window? */
ResType ldefType; /* Which LDEF to use */
MenuHandle theViewMenu; /* The picker view menu */
long viewMenuMask; /* Which items are enabled? */
Cell cellSize; /* Size for special view. */
MenuHandle iconMenu; /* Our menu */
} IconPickRec;
typedef IconPickRec *IconPickPtr;
typedef IconPickPtr *IconPickHandle;
/* Used only for editors. */
pascal void EditBirth(Handle thing, ParentHandle dad)
{
#pragma unused (thing, dad)
}
/* *********************************************************************************** */
pascal void PickBirth(ResType t, ParentHandle dad)
{
IconPickHandle pick;
IconPickPtr p; /* temp ptr for *pick */
MenuHandle theIconMenu;
pick = (IconPickHandle)NewHandle(sizeof(IconPickRec));
p = *pick;
p->father = dad; /* Back ptr to dad */
p->rType = t; /* Resource type that I understand */
p->viewBy = viewBySpecial; /* Special means we have our own LDEF to draw the icons */
p->ldefType = t; /* Which LDEF do we use? */
p->cellSize.h = listCellSizeH; /* Set the size of the cell. */
p->cellSize.v = listCellSizeV;
p->minWindowWidth = ICONMinWindowWidth;
p->minWindowHeight = ICONMinWindowHeight;
// Setup the list and create the window.
if (!DoPickBirth(noColor, true, graphical2DPicker, ResEdID(), (PickHandle)pick))
DisposHandle ((Handle)pick); // Error
else {
theIconMenu = GetMenu(iconMenuID);
DetachResource((Handle)theIconMenu); // Get our own copy of the menu.
(*pick)->iconMenu = theIconMenu;
}
}
/* *********************************************************************************** */
/* Everything is taken care of for us by PickEvent. */
pascal void DoEvent(EventRecord *evt, IconPickHandle pick)
{
PickEvent(evt, (PickHandle)pick);
if (evt->what == activateEvt) {
if (evt->modifiers & activeFlag)
InsertMenu((*pick)->iconMenu, 0);
else
DeleteMenu(iconMenuID);
DrawMBarLater(false);
}
}
/* *********************************************************************************** */
/* Everything is taken care of for us by PickInfoUp */
pascal void DoInfoUpdate(short oldID, short newID, PickHandle pick)
{
PickInfoUp(oldID, newID, pick);
}
/* *********************************************************************************** */
pascal Boolean IsThisYours (Handle thing, PickHandle pick)
{
#pragma unused (thing, pick)
return false;
}
/* *********************************************************************************** */
/* Everything is taken care of for us by PickMenu. */
pascal void DoMenu(short menu, short item, IconPickHandle pick)
{
if (menu == iconMenuID) {
/* Do something with the menu */
}
else {
if ((menu == fileMenu) && (item == closeItem)) {
DeleteMenu(iconMenuID);
DrawMBarLater(false);
DisposHandle((Handle)(*pick)->iconMenu);
}
PickMenu(menu, item, (PickHandle)pick);
}
}